#ifndef _ASK_DECODE_H_
#define _ASK_DECODE_H_

#include <sys/types.h>

struct ask_decoder
{
	u_int8_t *decoded_bytes;
	int num_decoded_bits;
	int decode_buffer_size;

	int samplerate;

	enum {
		STATE_NO_SYNC,
		STATE_FIRST_BIT,
		STATE_FIRST_SKIP,
		STATE_SECOND_BIT,
		STATE_SKIP_AND_EXPECT_0,
		STATE_EXPECT_0,
		STATE_SKIP_AND_EXPECT_1,
		STATE_EXPECT_1,
		STATE_SKIP_AND_PAD_1,
		STATE_PAD_1,
		STATE_SKIP_AND_PAD_2,
		STATE_PAD_2,
		STATE_SKIP_AND_READ_BIT,
		STATE_READ_BIT,
		STATE_LOST_SYNC,
	} state;

	int lastsample,samplecount;
	long long sum;

	int lastzero,currintegral;
	int firstintegral,threshold;
	int oneintegral,zerointegral;
	int pulsecount;
};

void init_ask_decoder(struct ask_decoder *dec,int samplerate);
void destroy_ask_decoder(struct ask_decoder *dec);

void provide_ask_input(struct ask_decoder *dec,int16_t *samples,int num_samples);

u_int8_t *ask_data_bytes(struct ask_decoder *dec);
int ask_data_length(struct ask_decoder *dec);

int is_ask_sync_found(struct ask_decoder *dec);
int is_ask_sync_lost(struct ask_decoder *dec);

#endif
